package antlr.parser;

import java.util.Stack;

public class CalcExecuteListener extends CalcBaseListener {

	Stack<Integer> stack = new Stack<>();
	
	@Override
	public void exitInt(CalcParser.IntContext ctx) {
		stack.add(Integer.parseInt(ctx.NUM().getText()));
	}
	
	public void exitAddSub(CalcParser.AddSubContext ctx) {
		int r = stack.pop();
		int l = stack.pop();
		stack.add(l + r);
	}
	
	public void enterMulDiv(CalcParser.AddSubContext ctx) {
		int r = stack.pop();
		int l = stack.pop();
		stack.add(l - r);
	}
	
	public int result() {
		return stack.pop();
	}
}
